//
// Created by meowch on 19-12-1.
//

#ifndef LIBDL_CORE_DICT_ITEM_H
#define LIBDL_CORE_DICT_ITEM_H

#include "c10/util/Exception.h"
#include "torch/ordered_dict.h"

template<typename Key, typename Value>
class Dict_item {
public:
    using core_type = typename torch::OrderedDict<Key, Value>::Item;
    core_type core;

    explicit Dict_item(const core_type *core) : core(*core) {};

    explicit Dict_item(core_type &core) : core(core) {};

    /// Returns a reference to the key.
    const Key &key() const noexcept {
        return core.key();
    }

    /// Returns a reference to the value.
    const Value &value() const noexcept {
        return core.value();
    }

    Value &value() noexcept {
        return core.value();
    }

    /// Returns a `(key, value)` pair.
    std::pair<Key, Value> pair() const noexcept {
        return core.pair();
    }
};

#endif //LIBDL_CORE_DICT_ITEM_H
